require "gosu.so"
=begin
$window=Gosu::Window.new

Sound
=end

module Audio

class AudioBase
  attr_reader :file, :type, :obj
  def initialize(file="")
    if file!=""
      @file=file
    end
  end
  def play
    @obj.play
  end
end

class Sound < AudioBase
  def initialize(file="")
    super(file)
    @obj=Gosu::Sample.new($window,@file)
  end
end

class Song < AudioBase
  def initialize(file="")
    super(file)
    @obj=Gosu::Song.new($window,@file)
  end  
end

class AudioFadeTo < Widget
  def initialize(sample, sample2, speed=0.05, volume=1)
    super(Button::Image,x1=0,y1=0,x2=0,y2=0,src="null.png",name="unnamed",acceptsticky=false)
    @sample=sample
    @end=sample2
    @volume=volume
    @sv=volume
    @ending=false
    @speed=speed
    delImage
    @sample.play
  end
  def intDraw
    @volume-=@speed
    @sample.volume=@volume
    if @sample.volume==0
      if @ending
        begin
          @sample.stop
        rescue
        
        end
        del
      else
        begin
          @sample.stop
        rescue
        
        end
        @sample=@end
        @sample.play(@sv)
        @speed*=-1
      end
    end
  end
end

class AudioFadeOut < Widget
  def initialize(sample, speed=0.05, volume=1)
    super(Button::Image,x1=0,y1=0,x2=0,y2=0,src="null.png",name="unnamed",acceptsticky=false)
    @sample=sample
    @volume=volume
    @speed=speed
    delImage
    @sample.play
  end
  def intDraw
    @volume-=@speed
    @sample.volume=@volume
    if @sample.volume==0
      begin
        @sample.stop
      rescue
      
      end
      del
    end
  end
end

class AudioFadeIn < Widget
  def initialize(sample, speed=0.05, volume=1)
    super(Button::Image,x1=0,y1=0,x2=0,y2=0,src="null.png",name="unnamed",acceptsticky=false)
    @sample=sample
    @volume=volume
    @speed=speed
    delImage
    @sample.play
  end
  def intDraw
    @volume+=@speed
    @sample.volume=@volume
    if @sample.volume==0
      begin
        @sample.stop
      rescue
      
      end
      del
    end
  end
end

end #module Audio

include Audio